home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 5
/
Amiga Tools 5.iso
/
tools
/
schule&wissen
/
bio
/
bio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-06
|
8KB
|
300 lines
/* A Biorythm program made by Henrik (Procyon) Wetterström */
/* For any reason contact me at: hwefri92@tufvan.hv.se */
/* */
/* This program was made after reading about Biorythms in */
/* the docs to Richard Smedley's "Biorythms v2.0". It made */
/* realize how easy it was to make one myself, and here is */
/* my result. For sure can a lot of optimizations can be */
/* done, but I don't feel like fiddle any more with it. */
/* Consider this program and source code as public domain. */
/* If you have plenty of use of it somehow, would it be */
/* fun to hear some cheering words from you, but you are */
/* for sure welcome to send me some parallel supercomputer */
/* for my thesis work. :-) */
/* Oh, well, there is only one catch, this source code or */
/* object code generated from it must not be stored on a */
/* storage available from any Microsoft application or OS. */
/* I bet this program is not the most excellent piece of */
/* source code, but maybe it can be of some guidance for a */
/* beginner. No guarantees for whatsoever is given by the */
/* the author.
/* I heard a rumour about a forth, intuition curve, which */
/* I added to the program. I hope this was correct... */
/*
To compile:
Standard SAS/C
sc bio.c CPU=68000 MATH=standard NOSTACKCHECK NOCHECKABORT NOMULTIPLEINCLUDES OPTIMIZE LINK NOWARNVOIDRETURN OPTIMIZERSIZE OPTIMIZERINLINELOCAL SMALLCODE SMALLDATA STRIPDEBUG OPTIMIZERSCHEDULER NOVERSION OPTIMIZERALIAS STRINGSECTION=near
68030/FPU SAS/C
sc bio.c CPU=68030 MATH=68881 NOSTACKCHECK NOCHECKABORT NOMULTIPLEINCLUDES OPTIMIZE LINK NOWARNVOIDRETURN OPTIMIZERSIZE OPTIMIZERINLINELOCAL SMALLCODE SMALLDATA STRIPDEBUG OPTIMIZERSCHEDULER NOVERSION OPTIMIZERALIAS STRINGSECTION=near
GCC
gcc bio.c -s -O3 -o bio
*/
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/screens.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/gfx.h>
#include <graphics/regions.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#define PCYCLE 23 /* Physical */
#define ECYCLE 28 /* Emotional */
#define ICYCLE 33 /* Intellectual */
#define NCYCLE 38 /* Intuition */
#define WINWDT 400
#define WINHGT 210
typedef struct st_bio {
int pp,ep,ip,np;
char today[10];
char birth[10];
int days;
} Bio;
void handle_events(struct Window *win);
struct Library *IntuitionBase;
struct Library *GadToolsBase;
struct Library *GfxBase;
struct Window *win;
int wtop,wleft,wright,wbottom; /* win offsets */
int wox,woy,wx,wy; /* plot area pos & size */
struct TextAttr fnt = { "topaz.font", 8, 0, 0, };
struct NewGadget ng[] = {
0,1, 88,13, (UBYTE *)"Quit", &fnt, 0, PLACETEXT_IN, NULL, NULL,
0,15, 88,13, (UBYTE *)"YY/MM/DD", &fnt, 1, PLACETEXT_BELOW, NULL, NULL
};
struct Gadget *glist = NULL;
struct Gadget *gads[2];
struct Gadget *gad;
struct Screen *scr;
struct RastPort *rp;
void *vi;
Bio *bio;
static Bio *get_bio(int y, int m, int d) {
const char *months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
static Bio bio;
time_t tp1,tp0;
struct tm *t1,t0={0,0,0,0,0,0,-1,-1,-1};
int ticks=60;
t0.tm_mday=d;
t0.tm_mon =m-1;
t0.tm_year=y;
tp0=mktime(&t0);
tp1=time(0);
t1=localtime(&tp1);
bio.days=(int)(difftime(tp1,tp0)/(ticks*60*24));
bio.pp=bio.days % PCYCLE;
bio.ep=bio.days % ECYCLE;
bio.ip=bio.days % ICYCLE;
bio.np=bio.days % NCYCLE;
sprintf(bio.birth,"%d-%s-%d",t0.tm_year, months[t0.tm_mon], t0.tm_mday);
sprintf(bio.today,"%d-%s-%d",t1->tm_year, months[t1->tm_mon], t1->tm_mday);
return &bio;
}
int openlibs( void ) {
if( IntuitionBase=OpenLibrary("intuition.library",37L) ) {
if( GadToolsBase=OpenLibrary("gadtools.library",37L) ) {
if( GfxBase=OpenLibrary("graphics.library",37L) ) return 1;
CloseLibrary((struct Library *)GadToolsBase);
}
CloseLibrary((struct Library *)IntuitionBase);
}
return 0;
}
void closelibs( void ) {
CloseLibrary((struct Library *)GadToolsBase);
CloseLibrary((struct Library *)IntuitionBase);
}
int getvisual( void ) {
if(scr=LockPubScreen(NULL)) {
wtop =scr->WBorTop+scr->BarHeight;
wleft =scr->WBorLeft+scr->BarHBorder;
wright =scr->WBorRight;
wbottom=scr->WBorBottom;
if(vi=GetVisualInfo(scr,TAG_END)) return 1;
UnlockPubScreen(NULL,scr);
}
return 0;
}
void print( char *s, int x, int y,int pen ) {
struct IntuiText it;
it.FrontPen=pen;
it.BackPen=0;
it.DrawMode=1;
it.LeftEdge=0;
it.TopEdge=0;
it.ITextFont=&fnt;
it.IText=s;
it.NextText=NULL;
PrintIText(rp,&it,wleft+x,wtop+y);
}
void plot2( int cycle, int color ) {
int pp,x;
double a,da;
SetAPen(rp,color);
pp=((bio->days)-17) % cycle;
a=((double)pp/(double)cycle)*2.0*PI;
da=((34.0*2*PI)/cycle)/(wx-14);
Move(rp,wox+7,woy+(wy/2)-(int)(((wy/2)-10)*sin(a)));
for(x=0; x<(wx-14); x++,a+=da) {
Draw(rp, wox+7+x, woy+(wy/2)-(int)(((wy/2)-10)*sin(a)));
}
}
void refresh(void) {
char ds[20];
char *s;
int y,m,d,i;
DrawBevelBox(rp,wleft+90,wtop+1,WINWDT-96,42+10,GT_VisualInfo,vi,GTBB_Recessed,1L,TAG_END);
DrawBevelBox(rp,wox-2,woy-1,wx+5,wy+3,GT_VisualInfo,vi,GTBB_Recessed,1L,TAG_END);
SetAPen(rp,0);
RectFill(rp,(SHORT)wox,(SHORT)woy,(SHORT)wox+wx,(SHORT)woy+wy);
SetAPen(rp,1);
Move(rp,wox, woy+(wy/2));
Draw(rp,wox+wx,woy+(wy/2));
Move(rp,wox+(wx/2),woy);
Draw(rp,wox+(wx/2),woy+wy);
for(i=wox+7; i<(wox+wx); i+=wx/35) {
WritePixel(rp,i,woy-1+(wy/2));
WritePixel(rp,i,woy+1+(wy/2));
}
s=((struct StringInfo *)gad->SpecialInfo)->Buffer;
if(strlen(s)) {
y=atoi(s);
m=atoi(s+3);
d=atoi(s+6);
if( y<0 || m<1 || m>12 || d<1 || d>31 ) return;
bio=get_bio(y,m,d);
print( bio->today,98,7,1);
sprintf(ds,"%d days old ",bio->days);
print( bio->birth,98,19,1);
print( ds,98,31,1);
print("Physical",260,31,1);
print("Emotional",260,7,7);
print("Intellectual",260,19,3);
print("Intuition",260,40,2);
plot2(PCYCLE,1);
plot2(ECYCLE,7);
plot2(ICYCLE,3);
plot2(NCYCLE,2);
}
}
int openwin( void ) {
WORD zoom[4]={0,12,180,12};
if( openlibs() ) {
if( getvisual() ) {
if ( gad=CreateContext( &glist ) ) {
ng[0].ng_VisualInfo=ng[1].ng_VisualInfo=vi;
ng[0].ng_TopEdge+=wtop;
ng[1].ng_TopEdge+=wtop;
ng[0].ng_LeftEdge+=wleft;
ng[1].ng_LeftEdge+=wleft;
gads[0] = gad = CreateGadget(BUTTON_KIND, gad, &ng[0],TAG_END );
gads[1] = gad = CreateGadget(STRING_KIND, gad, &ng[1], GTST_MaxChars,8,TAG_END );
zoom[1]=zoom[3]=wtop-1;
if( win=OpenWindowTags(NULL,
WA_Title, "Biorythms © Procyon",
WA_Width, WINWDT+wleft+wright,
WA_Height, WINHGT+wtop+wbottom,
WA_IDCMP, IDCMP_CLOSEWINDOW | BUTTONIDCMP | IDCMP_NEWSIZE,
WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
WA_Gadgets, glist,
WA_Zoom, zoom,
TAG_DONE, NULL
) ) {
rp=win->RPort;
wox=wleft+2;
woy=wtop+46+10;
wx=WINWDT-11;
wy=WINHGT-51-10;
refresh();
GT_RefreshWindow(win,NULL);
UnlockPubScreen(NULL,scr);
return 1;
}
if ( glist ) FreeGadgets( glist );
}
UnlockPubScreen(NULL,scr);
FreeVisualInfo(vi);
}
closelibs();
}
return 0;
}
void closewin( void ) {
CloseWindow(win);
FreeVisualInfo(vi);
if ( glist ) FreeGadgets( glist );
closelibs();
}
int main(int argc, char **argv) {
if(openwin()) {
handle_events(win);
}
closewin();
}
void handle_events(struct Window *win) {
int go=1;
ULONG sig;
struct IntuiMessage *imsg;
struct Gadget *gad;
while(go) {
sig=Wait( (1L<<win->UserPort->mp_SigBit) | (1L<<12) );
if(sig&(1L<<12)) go=0;
else {
while( go && (imsg=GT_GetIMsg(win->UserPort))) {
switch(imsg->Class) {
case CLOSEWINDOW:
go=0;
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(win);
GT_EndRefresh(win,1);
break;
case IDCMP_GADGETUP:
gad=(struct Gadget *)imsg->IAddress;
if(gad->GadgetID==0) go=0;
break;
}
if(go) refresh();
GT_ReplyIMsg(imsg);
}
}
}
}